from tkinter import *

root = Tk()
root.title("你最喜欢的城市？")
root.geometry("255x255")
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT,fill = Y)
lb = Listbox(root,yscrollcommand = scrollbar.set)
lb.pack()
for item in ["北京","上海","广州","深圳","长沙","武汉","郑州","重庆","成都","西安","杭州","南京","宁波","无锡","昆明","青岛","海南","天津","厦门","兰州","合肥","南昌","徐州"]:
    lb.insert(END,item)
thebutton = Button(root,text = "删除",command = lambda x=lb:x.delete(ACTIVE))
thebutton.pack()
var = StringVar()
var.set("你喜欢的城市在这！")
Label(root,textvariable=var).pack()

def search(event):
    var.set(lb.get(lb.curselection()))
lb.bind('<ButtonRelease-1>',search)

scrollbar.config(command = lb.yview)
mainloop()
